package com.tianhui.consignortwofei.mvp.ui.adapter;

import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.fgs.common.widget.itemView.DetailItemView;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.mvp.model.enty.VehicleInfo;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;

/**
 * @author fgs
 * @date 2020/8/27
 * @description
 **/
public class VehicleListAdapter extends RecyclerArrayAdapter<VehicleInfo> {

    public VehicleListAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new OrderListViewHolder(parent, R.layout.item_vehicle_list);
    }

    private class OrderListViewHolder extends BaseViewHolder<VehicleInfo> {

        private final TextView orderNumberTextView;
        private final TextView orderStatusTextView;
        private final TextView signatureTextView;
        private final DetailItemView oneDetailItemView;
        private final DetailItemView twoDetailItemView;
        private final DetailItemView threeDetailItemView;
        private final DetailItemView fourDetailItemView;
        private final DetailItemView fiveDetailItemView;
        private final DetailItemView sixthDetailItemView;
        private final DetailItemView timeDetailItemView;
        private final TextView submitTextView;
        private final Button auditButton;
        private final Button statusButton;


        public OrderListViewHolder(ViewGroup parent, int res) {
            super(parent, res);
            orderNumberTextView = getView(R.id.item_vehicle_list_topLeftTextView);
            orderStatusTextView = getView(R.id.item_vehicle_list_topRightTextView);

            signatureTextView = getView(R.id.item_vehicle_list_signatureTextView);
            signatureTextView.setVisibility(View.VISIBLE);
            oneDetailItemView = getView(R.id.item_vehicle_list_oneDetailItemView);
            twoDetailItemView = getView(R.id.item_vehicle_list_twoDetailItemView);
            threeDetailItemView = getView(R.id.item_vehicle_list_threeDetailItemView);
            fourDetailItemView = getView(R.id.item_vehicle_list_fourDetailItemView);
            fiveDetailItemView = getView(R.id.item_vehicle_list_fiveDetailItemView);
            fiveDetailItemView.setVisibility(View.VISIBLE);
            sixthDetailItemView = getView(R.id.item_vehicle_list_sixthDetailItemView);
            timeDetailItemView = getView(R.id.item_vehicle_list_timeDetailItemView);
            auditButton = getView(R.id.item_vehicle_list_auditButton);
            statusButton = getView(R.id.item_vehicle_list_statusButton);

            submitTextView = getView(R.id.item_vehicle_list_submitTextView);
            submitTextView.setText("重新生成挂靠声明");
            submitTextView.setVisibility(View.VISIBLE);

            addOnClickListener(R.id.item_vehicle_list_submitTextView);
            addOnClickListener(R.id.item_vehicle_list_signatureTextView);
            addOnClickListener(R.id.item_vehicle_list_operateButton);
            addOnClickListener(R.id.item_vehicle_list_editButton);
            addOnClickListener(R.id.item_vehicle_list_auditButton);
            addOnClickListener(R.id.item_vehicle_list_remarkButton);
            addOnClickListener(R.id.item_vehicle_list_statusButton);
        }

        @Override
        public void setData(VehicleInfo data) {
            super.setData(data);
            //司机姓名
            orderNumberTextView.setText("司机姓名：" + data.drivername);
            //车牌号：
            oneDetailItemView.setTitle("车牌号：");
            oneDetailItemView.setContent(data.vehiclenum);
            //挂车车牌号
            twoDetailItemView.setTitle("挂车车牌号：");
            twoDetailItemView.setContent(data.railerehicletvplatenumber);
            //车辆类型
            threeDetailItemView.setTitle("车辆类型：");
            threeDetailItemView.setContent(data.vehicletypename);
            //车牌颜色
            fourDetailItemView.setTitle("车牌颜色：");
            fourDetailItemView.setContent(data.vehiclenumcolortypename);
            //是否默认车辆
            fiveDetailItemView.setTitle("是否默认车辆：");
            if (!TextUtils.isEmpty(data.defaultvehicle) && data.defaultvehicle.equals("1")) {
                fiveDetailItemView.setContent("是");
            } else {
                fiveDetailItemView.setContent("否");

            }
            sixthDetailItemView.setTitle("备注：");
            sixthDetailItemView.setContent(data.remark);
            //创建时间
            timeDetailItemView.setTitle("创建时间：");
            timeDetailItemView.setContent(data.create_time);
            //状态
            orderStatusTextView.setText(Html.fromHtml(getAuthStatus(data)));
            //启用/停运状态
            if (!TextUtils.isEmpty(data.istatus)&&data.istatus.equals("1")){
                statusButton.setText("停运");
            }else {
                statusButton.setText("启用");
            }


            if (data.isaudit == 1) {
                auditButton.setVisibility(View.GONE);
            } else {
                auditButton.setVisibility(View.VISIBLE);
            }

        }
    }

    private String getAuthStatus(VehicleInfo info) {

        String status = "状态：<font color='#f52225'>" + "未审核" + "</font>";
        if (info == null) {
            return status;
        }
        if (info.isaudit == 0) {
            status = "状态：<font color='#f52225'>" + "未审核" + "</font>";
        } else if (info.isaudit == 1) {
            status = "状态：<font color='#008000'>" + "已审核" + "</font>";
        } else if (info.isaudit == 2) {
            status = "状态：<font color='#0000FF'>" + "待审核" + "</font>";
        }

        return status;

    }
}
